# -*- coding: utf-8 -*-
"""
作者: 肖麒
联系方式：QQ：1505448035
时间: 2025/8/4 16:23
文件作用：邮箱获取主页
"""
import re

import requests
from bs4 import BeautifulSoup


class RootshPage:
    def __init__(self):
        pass

    def get_rootsh_cookie(self):
        headers = {
            "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
            "Accept-Language": "zh-CN,zh;q=0.9",
            "Cache-Control": "no-cache",
            "Connection": "keep-alive",
            "Pragma": "no-cache",
            "Upgrade-Insecure-Requests": "1",
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36"
        }
        url = "http://rootsh.com:8003/"
        response = requests.get(url, headers=headers, verify=False)
        html = response.text
        # 使用 BeautifulSoup 解析 HTML
        soup = BeautifulSoup(html, 'html.parser')

        # 找到 id 为 domainlist 的 ul 元素
        domain_list = soup.find('ul', {'id': 'domainlist'})

        # 提取所有 li 元素中的文本内容
        suffix_list = [li.get_text() for li in domain_list.find_all('li')]

        # 找到邮件详情需要的替换字符

        # 正则表达式匹配两个replace中的字符串
        pattern = r'to\.replace\("@",\s*"([^"]*)"\)\.replace\("\.",\s*"([^"]*)"\)'

        match = re.search(pattern, response.text)

        replace_one = ''
        replace_two = ''
        if match:
            replace_one = match.group(1)  # !)*(*
            replace_two = match.group(2)  # -+-+-

        return response.cookies['mail'], suffix_list, replace_one, replace_two


if __name__ == '__main__':
    api = RootshPage()
    data = api.get_rootsh_cookie()
    print(data)
